using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Xml.Linq;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace ZhaoXi.Http.Client
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // httpClient 封装后的请求测试
            HttpClientRequestTest();

            //HttpWebRequestTest();

        }

        /// <summary>
        ///httpClient 封装后的请求测试
        /// </summary>
        private static void HttpClientRequestTest()
        {
            //========================================================
            //1、HttpCient基本应用--Get Post Put Delete请求方式的区分
            //========================================================
            {
                //Get请求无参数的
                HttpClient client = new HttpClient();
                string url = "http://localhost:5197/AANoParaApi/GetApiNoPara";
                string result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
                Console.WriteLine(result);

                //Post请求无参数的
                url = "http://localhost:5197/AANoParaApi/PostApiNoPara";
                result = client.PostAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                Console.WriteLine(result);

                //Put请求无参数的
                url = "http://localhost:5197/AANoParaApi/PutApiNoPara";
                result = client.PutAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                Console.WriteLine(result);

                //Delete请求无参数的
                url = "http://localhost:5197/AANoParaApi/DeleteApiNoPara";
                result = client.DeleteAsync(url).Result.Content.ReadAsStringAsync().Result;
                Console.WriteLine(result);
            }

            //========================================================
            //2、Http Get请求请求带参数需要满足的场景
            //========================================================
            //只能通过Url-也就是查询字符串传值，或者是通过Http请求的头信息来传值
            {
                //查询字符串
                {
                    //带简单参数int类型的Get请求
                    HttpClient client = new HttpClient();
                    string url = "http://localhost:5197/BBGetRequestParaApi/GetApiIntPara?i=1234";
                    string result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);

                    //带简单参数String类型的Get请求
                    url = "http://localhost:5197/BBGetRequestParaApi/GetApiStringPara?s=Richard";
                    result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);

                    //带简单参数String类型的Get请求,来自于查询字符串的解析
                    url = "http://localhost:5197/BBGetRequestParaApi/GetApiStringParaFromQuery?s=Richard";
                    result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);

                    //带简单参数String类型的Get请求,来自于请求头信息Header的解析
                    {
                        //通过Client复制头信息
                        url = "http://localhost:5197/BBGetRequestParaApi/GetApiStringParaFromHeadery";
                        client.DefaultRequestHeaders.Clear();
                        client.DefaultRequestHeaders.Add("s", "Richard");
                        result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
                        Console.WriteLine(result);


                        //通过HttpRequestMessage 设置头信息
                        HttpRequestMessage request = new HttpRequestMessage()
                        {
                            RequestUri = new Uri(url),
                            Method = HttpMethod.Get,
                        };
                        request.Headers.Clear();
                        request.Headers.Add("s", "Richard");
                        result = client.SendAsync(request).Result.Content.ReadAsStringAsync().Result;
                        Console.WriteLine(result);
                    }


                    //带实体类型参数的Get请求，来自于查询字符串的解析，请求的时候，还是使用QueryString方式
                    url = "http://localhost:5197/BBGetRequestParaApi/GetApiModelParaFromQuery?Id=234&Name=Richard&Email=Richard%40qq.com";
                    result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);

                }

                //头信息传值  
                {
                    HttpClient client = new HttpClient();
                    string url = "http://localhost:5197/BBGetRequestParaApi/GetApiStringParaFromHeadery";
                    HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, url);
                    httpRequest.Headers?.Add("s", WebUtility.UrlEncode("Richard"));
                    string result = client.SendAsync(httpRequest).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }
            }

            //====================================================
            //3、测试封装的Get请求帮助类库
            //=====================================================
            {
                string url = "http://localhost:5197/BBGetRequestParaApi/GetApiStringParaFromHeadery";
                HttpClientHelper httpClient = HttpClientHelper.GetInstance();
                Dictionary<string, string> diclist = new Dictionary<string, string>();
                diclist.Add("s", "Richard");
                string result = httpClient.Get(url, diclist).Content.ReadAsStringAsync().Result;
                Console.WriteLine(result);
            }
            //========================================================
            //4、Http Post请求的所有场景列举
            //========================================================
            {
                HttpClient client = new HttpClient();
                //带基本参数--int   ..... 带简单参数int类型的Post请求,是通过Url查询字符串
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiIntPara?i=1";
                    string result = client.PostAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                // //带基本参数--string 同上
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringPara?s=ss";
                    string result = client.PostAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求"   来自于查询字符串解析的，其他渠道解析不到
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromQuery?s=234";
                    string result = client.PostAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求,来自于请求头信息Header的解析，其他渠道解析不到
                //(注意：不能从头文件中传入实体，只能传入String)
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromHeadery";

                    client.DefaultRequestHeaders.Clear();
                    client.DefaultRequestHeaders.Add("s", WebUtility.UrlEncode("Richard"));
                    string result = client.PostAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求,来自于Body的解析，其他渠道解析不到
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromBody?s=Richard";
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject("Richard");  //必须要序列化
                    var content = new StringContent(data, Encoding.UTF8, "application/json");
                    string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求,来自于表单提交的解析,其他渠道解析不到
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromForm";
                    Dictionary<string, string> dic = new Dictionary<string, string>
                    {
                        { "s", "Richard" }
                    };
                    FormUrlEncodedContent content1 = new FormUrlEncodedContent(dic);
                    string result = client.PostAsync(url, content1).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求--默认情况
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelPara";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject(u);  //必须要序列化
                    StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
                    string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求，来自于查询字符串的解析
                {
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string url = $"http://localhost:5197/CCPostRequestApi/PostApiModelParaFromQuery?Id={u.Id}&Name={u.Name}&Email={u.Email}";
                    string result = client.PostAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求,来自于请求头信息Header的解析(注意：不能从头文件中传入实体，只能传入String)
                {
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelParaFromHeader";
                    client.DefaultRequestHeaders.Clear();
                    client.DefaultRequestHeaders.Add("U", "id,0,name,string,email,string");
                    string result = client.PostAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //实体类型参数的Post请求,来自于Body的解析
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelParaFromBody";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject(u);  //必须要序列化
                    StringContent content = new StringContent(data, Encoding.UTF8, "application/json");
                    string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求,来自于表单提交的解析
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelParaFromForm";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    Dictionary<string, string> dic = new Dictionary<string, string>
                    {
                        { "Id", u.Id.ToString() },
                        { "Name", u.Name },
                        { "Email", u.Email },
                    };
                    FormUrlEncodedContent content1 = new FormUrlEncodedContent(dic);
                    string result = client.PostAsync(url, content1).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }
            }

            //========================================================
            //5、测试封装的Post请求帮助类库
            //========================================================
            {
                HttpClientHelper client = HttpClientHelper.GetInstance();
                //带基本参数--int   ..... 带简单参数int类型的Post请求,是通过Url查询字符串
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiIntPara?i=1";
                    string result = client.PostAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                // //带基本参数--string 同上
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringPara?s=ss";
                    string result = client.PostAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求"   来自于查询字符串解析的，其他渠道解析不到
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromQuery?s=234";
                    string result = client.PostAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求,来自于请求头信息Header的解析，其他渠道解析不到
                //(注意：不能从头文件中传入实体，只能传入String)
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromHeadery";
                    Dictionary<string, string> diclist = new Dictionary<string, string>();
                    diclist.Add("s", "Richard");
                    string result = client.PostAsync(url, new List<KeyValuePair<string, string>>(), diclist).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求,来自于Body的解析，其他渠道解析不到
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromBody";
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject("Richard");  //必须要序列化 
                    string result = client.PostAsync(url, data).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求,来自于表单提交的解析,其他渠道解析不到
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromForm";
                    List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>()
                    {
                        new KeyValuePair<string, string>("s","Richard")
                    };
                    string result = client.PostAsync(url, keyValuePairs).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求--默认情况
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelPara";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject(u);  //必须要序列化 
                    string result = client.PostAsync(url, data).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求，来自于查询字符串的解析
                {
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string url = $"http://localhost:5197/CCPostRequestApi/PostApiModelParaFromQuery?Id={u.Id}&Name={u.Name}&Email={u.Email}";
                    string result = client.PostAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求,来自于请求头信息Header的解析(注意：不能从头文件中传入实体，只能传入String)
                {
                    //User u = new User
                    //{
                    //    Id = 234,
                    //    Name = "Richard",
                    //    Email = "Richard@qq.com"
                    //};
                    //string url = "http://localhost:5197/CCPostRequestApi/PostApiModelParaFromHeader";
                    //client.DefaultRequestHeaders.Clear();
                    //client.DefaultRequestHeaders.Add("U", "id,0,name,string,email,string");
                    //string result = client.PostAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                    //Console.WriteLine(result);
                }

                //实体类型参数的Post请求,来自于Body的解析
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelParaFromBody";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject(u);  //必须要序列化 
                    string result = client.PostAsync(url, data).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求,来自于表单提交的解析
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelParaFromForm";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    List<KeyValuePair<string, string>> dic = new List<KeyValuePair<string, string>>
                    {
                        new KeyValuePair<string, string>("Id", u.Id.ToString()),
                        new KeyValuePair<string, string>("Name", u.Name.ToString()),
                        new KeyValuePair<string, string>("Email", u.Email.ToString())
                    };
                    string result = client.PostAsync(url, dic).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }
            }


            //========================================================
            //6、测试封装的Put请求帮助类库
            //========================================================
            {
                HttpClientHelper client = HttpClientHelper.GetInstance();
                //带基本参数--int   ..... 带简单参数int类型的Put请求,是通过Url查询字符串
                {
                    string url = "http://localhost:5197/DDPutRequestApi/PutApiIntPara?i=1";
                    string result = client.Put(url).Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                // //带基本参数--string 同上
                {
                    string url = "http://localhost:5197/DDPutRequestApi/PutApiStringPara?s=ss";
                    string result = client.PutAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Put请求"   来自于查询字符串解析的，其他渠道解析不到
                {
                    string url = "http://localhost:5197/DDPutRequestApi/PutApiStringParaFromQuery?s=234";
                    string result = client.PutAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Put请求,来自于请求头信息Header的解析，其他渠道解析不到
                //(注意：不能从头文件中传入实体，只能传入String)
                {
                    string url = "http://localhost:5197/DDPutRequestApi/PutApiStringParaFromHeadery";
                    Dictionary<string, string> diclist = new Dictionary<string, string>();
                    diclist.Add("s", "Richard");
                    string result = client.PutAsync(url, new List<KeyValuePair<string, string>>(), diclist).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Put请求,来自于Body的解析，其他渠道解析不到
                {
                    string url = "http://localhost:5197/DDPutRequestApi/PutApiStringParaFromBody";
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject("Richard");  //必须要序列化 
                    string result = client.PutAsync(url, data).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Put请求,来自于表单提交的解析,其他渠道解析不到
                {
                    string url = "http://localhost:5197/DDPutRequestApi/PutApiStringParaFromForm";
                    List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>()
                    {
                        new KeyValuePair<string, string>("s","Richard")
                    };
                    string result = client.PutAsync(url, keyValuePairs).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Put请求--默认情况
                {
                    string url = "http://localhost:5197/DDPutRequestApi/PutApiModelPara";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject(u);  //必须要序列化 
                    string result = client.PutAsync(url, data).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Put请求，来自于查询字符串的解析
                {
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string url = $"http://localhost:5197/DDPutRequestApi/PutApiModelParaFromQuery?Id={u.Id}&Name={u.Name}&Email={u.Email}";
                    string result = client.PutAsync(url).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Put请求,来自于请求头信息Header的解析(注意：不能从头文件中传入实体，只能传入String)
                {
                    //User u = new User
                    //{
                    //    Id = 234,
                    //    Name = "Richard",
                    //    Email = "Richard@qq.com"
                    //};
                    //string url = "http://localhost:5197/DDPutRequestApi/PutApiModelParaFromHeader";
                    //client.DefaultRequestHeaders.Clear();
                    //client.DefaultRequestHeaders.Add("U", "id,0,name,string,email,string");
                    //string result = client.PutAsync(url, null).Result.Content.ReadAsStringAsync().Result;
                    //Console.WriteLine(result);
                }

                //实体类型参数的Put请求,来自于Body的解析
                {
                    string url = "http://localhost:5197/DDPutRequestApi/PutApiModelParaFromBody";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject(u);  //必须要序列化 
                    string result = client.PutAsync(url, data).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求,来自于表单提交的解析
                {
                    string url = "http://localhost:5197/DDPutRequestApi/PutApiModelParaFromForm";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    List<KeyValuePair<string, string>> dic = new List<KeyValuePair<string, string>>
                    {
                        new KeyValuePair<string, string>("Id", u.Id.ToString()),
                        new KeyValuePair<string, string>("Name", u.Name.ToString()),
                        new KeyValuePair<string, string>("Email", u.Email.ToString())
                    };
                    string result = client.PutAsync(url, dic).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine(result);
                }
            }
        }


        /// <summary>
        /// 
        /// </summary>
        private static void HttpWebRequestTest()
        {
            //====================================================
            //1、测试封装的Get请求帮助类库
            //=====================================================
            {
                string url = "http://localhost:5197/BBGetRequestParaApi/GetApiStringParaFromHeadery";
                HttpWebRequestHelper requestHelper = new HttpWebRequestHelper();
                Dictionary<string, string> diclist = new Dictionary<string, string>();
                diclist.Add("s", "Richard");
                HttpWebResponse response = requestHelper.Get(url, diclist);

                string result = response.ReponseToString();

                Console.WriteLine(result);
            }

            //========================================================
            //2、测试封装的Post请求帮助类库
            //========================================================
            {
                HttpWebRequestHelper requestHelper = new HttpWebRequestHelper();
                //带基本参数--int   ..... 带简单参数int类型的Post请求,是通过Url查询字符串
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiIntPara?i=1";
                    string result = requestHelper.Post(url).ReponseToString();
                    Console.WriteLine(result);
                }

                // //带基本参数--string 同上
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringPara?s=ss";
                    string result = requestHelper.Post(url).ReponseToString();
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求"   来自于查询字符串解析的，其他渠道解析不到
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromQuery?s=234";
                    string result = requestHelper.Post(url).ReponseToString();
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求,来自于请求头信息Header的解析，其他渠道解析不到
                //(注意：不能从头文件中传入实体，只能传入String)
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromHeadery";
                    Dictionary<string, string> diclist = new Dictionary<string, string>();
                    diclist.Add("s", "Richard");
                    string result = requestHelper.Post(url, diclist).ReponseToString();
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求,来自于Body的解析，其他渠道解析不到
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromBody";
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject("Richard");
                    string result = requestHelper.Post(url, data).ReponseToString();
                    Console.WriteLine(result);
                }

                //带简单参数String类型的Post请求,来自于表单提交的解析,其他渠道解析不到
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiStringParaFromForm";
                    Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
                    keyValuePairs.Add("s", "Richard");
                    string result = requestHelper.Post(url, keyValuePairs,null).ReponseToString();
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求--默认情况
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelPara";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject(u);  //必须要序列化 
                    string result = requestHelper.Post(url, data).ReponseToString();
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求，来自于查询字符串的解析
                {
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string url = $"http://localhost:5197/CCPostRequestApi/PostApiModelParaFromQuery?Id={u.Id}&Name={u.Name}&Email={u.Email}";
                    string result = requestHelper.Post(url).ReponseToString();
                    Console.WriteLine(result);
                }



                //实体类型参数的Post请求,来自于Body的解析
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelParaFromBody";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject(u);  //必须要序列化 
                    string result = requestHelper.Post(url, data).ReponseToString();
                    Console.WriteLine(result);
                }

                //带实体类型参数的Post请求,来自于表单提交的解析
                {
                    string url = "http://localhost:5197/CCPostRequestApi/PostApiModelParaFromForm";
                    User u = new User
                    {
                        Id = 234,
                        Name = "Richard",
                        Email = "Richard@qq.com"
                    };
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    dic.Add("Id", u.Id.ToString());
                    dic.Add("Name", u.Name.ToString());
                    dic.Add("Email", u.Email.ToString());
                    string result = requestHelper.Post(url, dic).ReponseToString();
                    Console.WriteLine(result);
                }
            }
        }
    }
}
